import os.path
import datetime
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdrivermanager_cn import ChromeDriverManager


class Driver:
    driver=""
    def __init__(self):
        options=webdriver.ChromeOptions()
        self.driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
        self.driver.implicitly_wait(2)
    def getScreenShot(self):
        #创建屏幕截图
        #图片文件名称：./2025/5/10-150440.png
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        if not os.path.exists("E:/测试/auto-CodePilot/images/"+dirname):
            os.mkdir("E:/测试/auto-CodePilot/images/"+dirname)
        filename=sys._getframe().f_back.f_code.co_name+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("E:/测试/auto-CodePilot/images/"+dirname+"/"+filename)
        #sys._getframe().f_back.f_code.co_name获取调用方法名
pilotDriver=Driver()